var ajaxCount=0;
var ckeditor;
	 function pageload(hash,div,form) {
	 	// hash doesn't contain the first # character.
	 	if(!div)div='mainContent';
		 if(hash) {
		 	// restore ajax loaded state
		 	
		 	hash=hash.replace(/-/g,'/');
		 	ajax(div,hash,form);
		 } else {
		 	// start page
		 	ajax(div,'homes/home',form);
		 }
	}
	// <!-- 
	// History manager
		$(document).ready(function() {
		    $.history.init(pageload);		   
		});
    // -->
	
	
	
	

	function activateEditor(id,config) {
	    //activeEditors[activeEditors.length] = id
	    //toggleEditor(id)
		if(config==undefined)
			config={toolbar:'DToolbar'};
			
		if ( ckeditor )
			return;
		ckeditor = CKEDITOR.replace( id,config);
	}
	
	function setEditorContent(html) {
	    //activeEditors[activeEditors.length] = id
	    //toggleEditor(id)
		
			
		if ( ckeditor )
			return;
		ckeditor.setData(html);
	}
	
	function deactivateEditors() {
	    /*
		for(x=0;x<activeEditors.length;x++) {
	        toggleEditor(activeEditors[x])
	    }
	    activeEditors.length = 0
	    */
		if ( !ckeditor )
			return;

		// Retrieve the editor contents. In an Ajax application, this data would be
		// sent to the server or used in any other way.
		//document.getElementById( 'editorcontents' ).innerHTML = html = editor.getData();
		//document.getElementById( 'contents' ).style.display = '';

		// Destroy the editor.		
		ckeditor.destroy();
		ckeditor = null;
		
	}
	
	

	// other function for website
	
	/*reset form*/
	function resetForm(form){
		document.getElementById(form).reset();
	}
	/*functionn to clear content of a box*/
	function closeBox(box,destinationBox){
		deactivateEditors();
		if(document.getElementById(box)!=null)
			document.getElementById(box).innerHTML="";
		if(destinationBox!=undefined)scrollTopTo(destinationBox);
	}
	/*function use in permission module, to check/uncheck all box*/
	function changestate(classes){
		
		if(document.getElementById(classes+'All').checked){
			$("input[class='checkbox " + classes + "']").attr('disabled','true');
			$("label[class=" + classes + "]").attr('style','color:#dbdbdb');
			
		}
		else{
			$("input[class='checkbox " + classes + "']").removeAttr('disabled');
			$("label[class=" + classes + "]").attr('style','color:#666');
			
		}

	}
	
	function empty(str){
		var temp="";
		var len=0;
		temp=str;
		while(len!=temp.length){
			len=temp.length;
			temp=temp.replace(" ","");
			temp=temp.replace("\r","");
			temp=temp.replace("\n","");
		}
		if(temp=="")return true;
		return false;
	}
	
	function _JS_emailCheck (input_object) {
	var emailStr = input_object.value;
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,4})\.(\d{1,4})\.(\d{1,4})\.(\d{1,4})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	
	if (matchArray==null) {
		return _JS_onError(input_object,"This address seems to be incorrect (they usually have an @ symbol)")
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null) {
		return _JS_onError(input_object,"The username doesn't seem to be valid.")
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				return _JS_onError(input_object,"Destination IP address is invalid!")
            }
		}
		return true
	}
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		return _JS_onError(input_object,"The domain name doesn't seem to be valid.")
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 ||	domArr[domArr.length-1].length>4) {
		return _JS_onError(input_object,"The address must end in a three-letter domain, or two letter country.")
	}
	if (len<2) {
		return _JS_onError(input_object,"This address is missing a hostname!")
	}
	return true;
}
	
		setInterval("removeMessage()",10000);
	
	
